package Solutions

func pancakeSort(arr []int) []int {
    length:=len(arr)
    ans:=make([]int,0,8)
    for i:=0;i<length;i++{
        maxI:=findMax(arr[:length-i])
        ans=append(ans,maxI+1)
        for l,r:=0,maxI;l<r;l,r=l+1,r-1{
            arr[l],arr[r]=arr[r],arr[l]
        }
        ans=append(ans,length-i)
        for l,r:=0,length-i-1;l<r;l,r=l+1,r-1{
             arr[l],arr[r]=arr[r],arr[l]
        }
    }
    return ans
}
func findMax(arr []int)int{
    maxInd:=0
    for i,v:=range arr{
        if v>arr[maxInd]{
            maxInd=i
        }
    }
    return maxInd
}